package o;

import android.os.AsyncTask;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.card.base.bean.DependAppBean;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

public class djz {

    static class a implements o.dqw.c {
        private CountDownLatch ˊ;
        private List<b> ˋ;
        private DependAppBean ॱ;

        public a(DependAppBean dependAppBean, CountDownLatch countDownLatch, @NonNull List<b> list) {
            this.ॱ = dependAppBean;
            this.ˊ = countDownLatch;
            this.ˋ = list;
        }

        public void ˋ(SessionDownloadTask sessionDownloadTask) {
            b bVar = new b();
            bVar.ˋ(this.ॱ);
            bVar.ˏ(sessionDownloadTask);
            this.ˋ.add(bVar);
            this.ˊ.countDown();
            Logger.ˎ("DependBundleAppDownloadManager", "latch size down");
        }

        public void ॱ() {
            Logger.ˋ("DependBundleAppDownloadManager", "get app bundle info fail. ");
            this.ˊ.countDown();
            Logger.ˎ("DependBundleAppDownloadManager", "latch size down");
        }
    }

    public static class b {
        private SessionDownloadTask ˊ;
        private DependAppBean ˎ;

        public SessionDownloadTask ˋ() {
            return this.ˊ;
        }

        public void ˏ(SessionDownloadTask sessionDownloadTask) {
            this.ˊ = sessionDownloadTask;
        }

        public DependAppBean ॱ() {
            return this.ˎ;
        }

        public void ˋ(DependAppBean dependAppBean) {
            this.ˎ = dependAppBean;
        }
    }

    public interface c {
        void ॱ(@Nullable List<b> list);
    }

    static class e extends AsyncTask<List<DependAppBean>, Void, List<b>> {
        private c ˏ;

        @Nullable
        protected /* synthetic */ Object doInBackground(Object[] objArr) {
            return ˏ((List[]) objArr);
        }

        protected /* synthetic */ void onPostExecute(Object obj) {
            ˎ((List) obj);
        }

        public e(c cVar) {
            this.ˏ = cVar;
        }

        @Nullable
        protected List<b> ˏ(List<DependAppBean>... listArr) {
            if (listArr == null || listArr.length <= 0) {
                return null;
            }
            return djz.ˎ(listArr[0]);
        }

        protected void ˎ(List<b> list) {
            super.onPostExecute(list);
            if (this.ˏ != null) {
                this.ˏ.ॱ(list);
            }
        }
    }

    public static void ˏ(List<DependAppBean> list, c cVar) {
        Logger.ˎ("DependBundleAppDownloadManager", "getDependDownloadTaskListAsync");
        new e(cVar).execute(new List[]{list});
    }

    private static List<b> ˎ(List<DependAppBean> list) {
        List<b> arrayList = new ArrayList();
        if (CollectCheck.isEmpty((List) list)) {
            Logger.ˋ("DependBundleAppDownloadManager", "dpbeanList is empty.");
        } else {
            Logger.ˎ("DependBundleAppDownloadManager", "latch size=" + list.size());
            CountDownLatch countDownLatch = new CountDownLatch(list.size());
            for (DependAppBean dependAppBean : list) {
                BaseDistCardBean ˋ = dependAppBean.ˋ();
                if (Logger.ˎ()) {
                    Logger.ˏ("DependBundleAppDownloadManager", dependAppBean.toString());
                }
                if (dependAppBean.packingType_ == 1) {
                    Logger.ˎ("DependBundleAppDownloadManager", "is bundle app.");
                    new dqw().ˏ(ˋ, new a(dependAppBean, countDownLatch, arrayList));
                } else {
                    SessionDownloadTask sessionDownloadTask = new SessionDownloadTask();
                    b bVar = new b();
                    bVar.ˋ(dependAppBean);
                    bVar.ˏ(sessionDownloadTask);
                    arrayList.add(bVar);
                    Logger.ˎ("DependBundleAppDownloadManager", "latch size down");
                    countDownLatch.countDown();
                }
            }
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                Logger.ˋ("DependBundleAppDownloadManager", "InterruptedException");
            } finally {
                arrayList = "DependBundleAppDownloadManager";
                Logger.ˎ(arrayList, "getDependDownloadTaskList end.");
            }
        }
        return arrayList;
    }
}
